/**
 * 新增
 * @param vue {Vue} vue 对象
 * @param param {Object} 参数
 * @param success {Function} 请求成功回调方法
 * @param finallyFun {Function} 请求最终回调方法
 * */
export function create(vue, param, success, finallyFun) {
  vue.$request.post({
    url: "operationAid/KeyWordUsageRecordGroup/create",
    params: param,
    success: success,
    finally: finallyFun
  });
}

export function update(vue, params, success, finallyFun) {
  vue.$request.post({
    url: "operationAid/KeyWordUsageRecordGroup/update",
    params: params,
    success: success,
    finally: finallyFun
  });
}

export function remove(vue,ids, success, finallyFun) {
  vue.$request.post({
    url: "operationAid/KeyWordUsageRecordGroup/delete",
    params: {
      jsonIds: JSON.stringify(ids)
    },
    success:success,
    finally: finallyFun
  })
}

export function getList(vue,params, success, finallyFun) {
  vue.$request.post({
    url: "operationAid/KeyWordUsageRecordGroup/list",
    params: params,
    success: success,
    finally: finallyFun,
    allError: err => {
      console.log(err);
    }
  });
}

export function getOptions(vue,categoryName,success, finallyFun) {
  getList(vue,{categoryName: categoryName},r=> {
    r = r.map(({ id, name,categoryName }) => ({ id, name,categoryName }))
    r.unshift({id: 0,name: "未分组"})
    success(r)
  },finallyFun)
}

export function groupIdToGroupName(id,options){
  if (id){
    let r = options.find(item => id === item.id);
    if (r){
      return r.name || '编号: ' + id
    }else{
      return '编号: ' + id
    }

  }else{
    return "未分组"
  }
}